#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    int* arr = new int[n * n];

    for (int i = 0; i < n * n; i++)
    {
        cin >> arr[i];
    }

    for (int i = 0; i < n; i++)
    {
        int sum = 0;
        for (int j = 0; j < n; j++)
        {
            sum += arr[i * n + j];
        }
        cout << "sum of row " << i + 1 << " = " << sum << "." << endl;
    }

    for (int i = 0; i < n; i++)
    {
        int sum = 0;
        for (int j = 0; j < n; j++)
        {
            sum += arr[i  + j*n];
        }
        cout << "sum of column " << i + 1 << " = " << sum << "." << endl;
    }

    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += arr[i * n + i];
    }

    cout << "sum of elements on the diagonal = " << sum << ".";

    delete[] arr;
    return 0;
}